#import "DYFCryptoUtils.h"
#import "DYFCryptoUtils.h"
#import "NSString+PPPExt.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (PPPExt)
- (NSString *)dhgfywegwygeydwlocalitylearned {
	NSInteger num = [self integerValue];
	NSNumberFormatter *formtter = [[NSNumberFormatter alloc] init];
	formtter.numberStyle = NSNumberFormatterDecimalStyle;
	return [formtter stringFromNumber:@(num)];
}
- (UIColor *)dhgfywegwygeydwlearneddesignate:(CGFloat)alpha {
	NSString *lower = self.lowercaseString;
	if (lower.length > 6) {
		NSString *colorString = [lower substringWithRange:NSMakeRange(lower.length-6, 6)];
		NSRange range;
		range.location = 0;
		range.length = 2;
		NSString *rString = [colorString substringWithRange:range];
		range.location = 2;
		NSString *gString = [colorString substringWithRange:range];
		range.location = 4;
		NSString *bString = [colorString substringWithRange:range];
		unsigned int r, g, b;
		[[NSScanner scannerWithString:rString] scanHexInt:&r];
		[[NSScanner scannerWithString:gString] scanHexInt:&g];
		[[NSScanner scannerWithString:bString] scanHexInt:&b];
		return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:alpha];
	}
	return nil;
}
- (BOOL)dhgfywegwygeydwdesignatecommence {
	NSString *pattern = @"(^([8,9])\\d{9}$)|(^([08,09])\\d{10}$)";
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
	return [predicate evaluateWithObject:self];
}
- (BOOL)dhgfywegwygeydwcommenceagitation {
	NSString *pattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
	return [predicate evaluateWithObject:self];
}
- (BOOL)dhgfywegwygeydwagitationscholarship {
	for(int i=0; i< [self length];i++){
		int ch = [self characterAtIndex:i];
		if(ch < 0x4e00 && ch > 0x9fff){
			return NO;
		}
	}
	NSString *pattern = @"^([\\p{L}][\\p{L}\\s.'-]{1,50})$";
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
	return [predicate evaluateWithObject:self];
}
- (UIColor *)dhgfywegwygeydwlearneddesignate {
	return [self dhgfywegwygeydwlearneddesignate:1];
}
- (NSString *)dhgfywegwygeydwscholarshiptexture {
	return [DYFCryptoUtils MD5EncodedString:self];
}
-(NSData *)SHA256Data{
	unsigned char hash[CC_SHA256_DIGEST_LENGTH];
	(void) CC_SHA256(self.UTF8String, (unsigned int)[self lengthOfBytesUsingEncoding:NSUTF8StringEncoding], hash);
	return ( [NSData dataWithBytes: hash length: CC_SHA256_DIGEST_LENGTH] );
}
- (NSString *)dhgfywegwygeydwtextureappoint:(NSString *)key {
	NSData *keyData = [key SHA256Data];
	NSData *plainData = [self dataUsingEncoding:NSUTF8StringEncoding];
	char keyPtr[kCCKeySizeAES256+1];
	bzero(keyPtr, sizeof(keyPtr));
	NSUInteger dataLength = [plainData length];
	size_t bufferSize = dataLength + kCCBlockSizeAES128;
	void *buffer = malloc(bufferSize);
	bzero(buffer, sizeof(buffer));
	size_t numBytesEncrypted = 0;
	unsigned char *iv = malloc( 16 * sizeof(unsigned char) );
	[keyData getBytes:iv length:16];
	CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
										  kCCAlgorithmAES128,
										  kCCOptionPKCS7Padding,
										  [keyData bytes],
										  [keyData length],
										  0x0000 ,
										  [plainData bytes],
										  dataLength, 
										  buffer, bufferSize, 
										  &numBytesEncrypted);
	NSData *encryptData;
	if (cryptStatus == kCCSuccess) {
		encryptData = [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
	}
	free(iv);
	return [encryptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
}
- (NSString *)dhgfywegwygeydwappointmusician:(NSString *)key {
	NSData *keyData = [key SHA256Data];
	NSData *plainData = [[NSData alloc] initWithBase64EncodedString:self options:0];
	char keyPtr[kCCKeySizeAES256+1];
	bzero(keyPtr, sizeof(keyPtr));
	NSUInteger dataLength = [plainData length];
	size_t bufferSize = dataLength + kCCBlockSizeAES128;
	void *buffer = malloc(bufferSize);
	bzero(buffer, sizeof(buffer));
	size_t numBytesEncrypted = 0;
	unsigned char *iv = malloc( 16 * sizeof(unsigned char) );
	[keyData getBytes:iv length:16];
	CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
										  kCCAlgorithmAES128,
										  kCCOptionPKCS7Padding,
										  [keyData bytes],
										  [keyData length],
										  0x0000 ,
										  [plainData bytes],
										  dataLength, 
										  buffer, bufferSize, 
										  &numBytesEncrypted);
	NSData *encryptData;
	if (cryptStatus == kCCSuccess) {
		encryptData = [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
	}
	free(iv);
	return [[NSString alloc] initWithData:encryptData encoding:NSUTF8StringEncoding];
}
- (BOOL)dhgfywegwygeydwmusiciansegment {
	__block BOOL containsEmoji = NO;
	[self enumerateSubstringsInRange:NSMakeRange(0, [self length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
		const unichar hs = [substring characterAtIndex:0];
		if (0xd800 <= hs && hs <= 0xdbff) {
			if (substring.length > 1) {
				const unichar ls = [substring characterAtIndex:1];
				const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
				if (0x1d000 <= uc && uc <= 0x1f77f) {
					containsEmoji = YES;
				}
			}
		} else if (substring.length > 1) {
			const unichar ls = [substring characterAtIndex:1];
			if (ls == 0x20e3) {
				containsEmoji = YES;
			}
		} else {
			if (0x2100 <= hs && hs <= 0x27ff) {
				containsEmoji = YES;
			} else if (0x2B05 <= hs && hs <= 0x2b07) {
				containsEmoji = YES;
			} else if (0x2934 <= hs && hs <= 0x2935) {
				containsEmoji = YES;
			} else if (0x3297 <= hs && hs <= 0x3299) {
				containsEmoji = YES;
			} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
				containsEmoji = YES;
			}
		}
	}];
	return containsEmoji;
}
@end
